package BBDD;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;


import DAO.TramosHorariosDAO;

public class ManageTramosHorarios {
	private Connection conn;
	private Statement pstmt;
	private ResultSet rs;
	private String query;
	private ManageDB abreConn;
	private Vector<TramosHorariosDAO> tramosHorarios=new Vector<TramosHorariosDAO>();

	public ManageTramosHorarios() {

	}

	public void loadDataTramosHorarios(String query) {
		this.query = query;
		conn = abreConn.getConnection();
		
		try {
			pstmt = conn.createStatement();
			rs = pstmt.executeQuery(query);		
			
			while (rs.next()) {
				int idtramo = rs.getInt(1);
				String horaInicioTramo  = rs.getString(2);
				String horaFinTramo = rs.getString(3);				
				setTramosHOrarios(new TramosHorariosDAO(idtramo, horaInicioTramo, horaFinTramo));

			}

		} catch (SQLException ex) {
			Logger.getLogger(ManageTramosHorarios.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {
			try {
				rs.close();
				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}

		}
	}

	public void updateTramosHorarios(String query) {
		this.query = query;

		conn = abreConn.getConnection();

		try {

			pstmt = conn.prepareStatement(query);
			pstmt.execute(query);
		} catch (SQLException ex) {
			Logger.getLogger(ManageAlumno.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {

			try {

				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public void deleteTramosHorarios(String query) {
		this.query = query;

		conn = abreConn.getConnection();

		try {

			pstmt = conn.prepareStatement(query);
			pstmt.execute(query);
		} catch (SQLException ex) {
			Logger.getLogger(ManageAlumno.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {

			try {

				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public String getOldQuery() {
		return query;
	}

	public Vector<TramosHorariosDAO> getTramosHorarios() {
		return tramosHorarios;
	}

	public void setTramosHOrarios(TramosHorariosDAO tramosHorarios) {
		this.tramosHorarios.add(tramosHorarios);
	}
}
